<template>
  <div class="wrapper">
      <swiper :options="swiperOption">
        <swiper-slide v-for="(page,index) in pages" :key="index">
          <div class="icon-items"  v-for="(item,index) in page" :key="index">
            <img class="icon-img" :src="item.imgUrl" alt="">
            <p class="text">{{item.desc}}</p>
          </div>
        </swiper-slide>
      </swiper>
  </div>
</template>

<script>
export default {
  name: 'HomeIcons',
  props: {
    icons: Array
  },
  data () {
    return {
      swiperOption: {
        autoplay: false
      }
    }
  },
  computed: {
    pages () {
      const pages = []
      this.icons.forEach((ele, index) => {
        let page = Math.floor(index / 8)
        if (!pages[page]) {
          pages[page] = []
        }
        pages[page].push(ele)
      })
      return pages
    }
  }
}
</script>

<style lang="stylus" scoped>
.wrapper >>> .swiper-container{
  height:100%;
}
.wrapper >>> .swiper-slide{
  display:flex;
  flex-wrap:wrap;
  height: 100%;
}
.wrapper{
  overflow:hidden;
  height:50vw;
    .icon-items{
      text-align:center;
      width:25%;
      height:50%;
      display:flex;
      flex-direction: column;
      justify-content: center;
      .icon-img{
        width:50%;
        height:50%;
        display:block;
        margin: 0 auto 0.1rem;
      }
    }
}
</style>
